import _extends from 'babel-runtime/helpers/extends';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
/**
 * 带权限校验的Button组件，兼容antd.Button
 * @Author: ljq
 * @Date: 2018-10-11 14:23:05
 */
import * as React from 'react';
import { Button, Tooltip, Icon } from 'antd';
import AuthCheck from '../auth-check';

var ButtonAuth = function (_React$Component) {
    _inherits(ButtonAuth, _React$Component);

    function ButtonAuth() {
        _classCallCheck(this, ButtonAuth);

        var _this = _possibleConstructorReturn(this, (ButtonAuth.__proto__ || Object.getPrototypeOf(ButtonAuth)).apply(this, arguments));

        _this.getButton = function () {
            var _this$props = _this.props,
                children = _this$props.children,
                type = _this$props.type,
                title = _this$props.title,
                buttonicon = _this$props.buttonicon;

            if (type == 'text') {
                return React.createElement(
                    Button,
                    _extends({}, _this.props, { type: 'default', className: 'btn-text' }),
                    children
                );
            } else if (type == 'icon') {
                return React.createElement(
                    Tooltip,
                    { title: title },
                    React.createElement(
                        Button,
                        _extends({}, _this.props, { type: 'default', className: 'btn-text' }),
                        React.createElement(Icon, { type: buttonicon }),
                        children
                    )
                );
            } else {
                return React.createElement(
                    Button,
                    _this.props,
                    children
                );
            }
        };
        return _this;
    }

    _createClass(ButtonAuth, [{
        key: 'render',
        value: function render() {
            var _props = this.props,
                check = _props.check,
                storagetype = _props.storagetype;

            if (storagetype && storagetype === "localStorage") {
                return React.createElement(
                    AuthCheck,
                    { check: check, storagetype: 'localStorage' },
                    this.getButton()
                );
            }
            return React.createElement(
                AuthCheck,
                { check: check },
                this.getButton()
            );
        }
    }]);

    return ButtonAuth;
}(React.Component);

export default ButtonAuth;